package com.ty.xiaoyu.util;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

public class HttpServletRequestUtil {

    public static int getInt(HttpServletRequest request, String key) {
        try {
            return Integer.decode(request.getParameter(key));
        } catch (Exception e) {
            return -1;
        }
    }

    public static String getString(HttpServletRequest request, String key) {
        try {
            String result = request.getParameter(key);
            if (result != null) {
                result = result.trim();
            }
            if ("".equals(result)) {
                result = null;
            }
            return result;
        } catch (Exception e) {
            return null;
        }
    }

    public static List<String> getStringList(HttpServletRequest request, String key) {
        try {
            List<String> list = Arrays.asList(request.getParameterValues(key));
            return list;
        } catch (Exception e) {
            return null;
        }
    }

//    public static List<MultipartFile> getMultipartFileList(HttpServletRequest request, String key) {
//        try {
//            List<String> list = Arrays.asList(request.getParameterValues(key));
//            return list;
//        } catch (Exception e) {
//            return null;
//        }
//    }
}
